package a.a;

import java.util.ArrayList;
import java.util.List;
import a.b.SectionAdapter;
import android.app.ListActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.RecyclerListener;
import android.widget.ListView;
import android.widget.TextView;

public class SectionAdapterTutorialActivity extends ListActivity implements RecyclerListener {
	static List<String> ITEMS = new ArrayList<String>();
	static {
		// addSection 1
		ITEMS.add("A1");
		// addSection 2
		ITEMS.add("B1");
		// addSection 3
		ITEMS.add("C1");
		// addSection 4
		ITEMS.add("D1");
		// addSection 5
		ITEMS.add("E1");
		// addSection 6
		ITEMS.add("F1");
		// addSection 7
		ITEMS.add("G1");// item=17, section=7
		
		ITEMS.add("A1");
		// addSection 2
		ITEMS.add("B1");
		// addSection 3
		ITEMS.add("C1");
		// addSection 4
		ITEMS.add("D1");
		// addSection 5
		ITEMS.add("E1");
		// addSection 6
		ITEMS.add("F1");
		// addSection 7
		ITEMS.add("G1");// item=17, section=7
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setListAdapter(new SectionAdapter(this, R.layout.section, R.layout.item, ITEMS) {
			@Override
			protected void getSectionView(int position, View view, ViewGroup parent) {
				String text = getItem(position);
				TextView tv = (TextView) view.findViewById(R.id.text);
				tv.setText(text);
			}

			@Override
			protected void getContentView(int position, View view, ViewGroup parent) {
				String text = getItem(position);
				TextView tv = (TextView) view.findViewById(R.id.text);
				tv.setText(text);
			}
		});
		getListView().setCacheColorHint(Color.TRANSPARENT);
		getListView().setItemsCanFocus(true);
		getListView().setRecyclerListener(this);

	}

	@Override
	public void onMovedToScrapHeap(View v) {
		Log.d("TAG", "onMovedToScrapHeap()" + v);
	};

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Log.d("TAG", "onListItemClick()" + position);
	}
}